void function(){
	if(!$){console.log('jQuery is not definde');return;};
	$.fn.extend({
		wodsyimgdrag:function(){
			var obj = $(this),toObj = arguments.length>0?arguments[0]:$('[imgdrag="to"]'),scrollTimer,arg = {},moveObj,noimg = 'images/noimg.png',obj_,
			toObjSpace = (function(){
				var arr = [];
				toObj.each(function(){
					var arrli = [$(this).offset().left,$(this).offset().top,$(this).offset().left+$(this).width(),$(this).offset().top+$(this).height()];
					arr.push(arrli);
				});
				$.each(arr,function(i,o){
					var div = $('<div style="background:#000;position:absolute;"></div>');
					div.css({'left':o[0],'top':o[1],'width':o[2]-o[0],'height':o[3]-o[1]});

					//$('body').append(div);
				})
				return arr;
			})(),
			haveimg = function(thisimgsrc){
				return thisimgsrc.indexOf('noimg.png')<0?false:true;
			},
			moveOver = function(){
				var ind;
				$.each(toObjSpace,function(i,o){
					if(arg.movemouseX>o[0]&&arg.movemouseX<o[2]&&arg.movemouseY>o[1]&&arg.movemouseY<o[3]){
						ind = i;
					}
				});
				if(typeof ind!=='undefined'){
					toObj.removeClass('dragImgOver');
					toObj.eq(ind).addClass('dragImgOver');
				}else{
					toObj.removeClass('dragImgOver');
				};
				return ind;
			},
			upMoust = function(e){
				var ind = moveOver(),thisimgsrc = toObj.eq(ind).find('img').attr('src'),oldsrc = $('[imgdrag="moveObj"]').find('img').attr('src');
				$(document).unbind();
				$('.dragImgOver').removeClass('dragImgOver');
				if(typeof ind!=='undefined'){
					if(obj_.attr('imgdrag')!='_img')
						if(!haveimg(thisimgsrc)){
							toObj.eq(ind).find('img').css({'position':'fixed','left':toObj.eq(ind).find('img').offset().left,'top':toObj.eq(ind).find('img').offset().top - $(window).scrollTop(),'width':toObj.eq(ind).find('img').width(),'height':toObj.eq(ind).find('img').height()}).animate({left:obj_.offset().left,top:obj_.offset().top - $(window).scrollTop(),width:obj_.width(),height:obj_.height()},200,function(){$(this).remove();obj_.attr('src',thisimgsrc)});
							toObj.eq(ind).append('<img>');
						}else{
							obj_.unbind();
						}
					var src = $('[imgdrag="moveObj"]').animate({left:toObj.eq(ind).find('img').offset().left,top:toObj.eq(ind).find('img').offset().top - $(window).scrollTop(),width:toObj.eq(ind).find('img').width(),height:toObj.eq(ind).find('img').height()},200,function(){$(this).remove();toObj.eq(ind).find('img').attr('src',src);toObj.eq(ind).find('img').wodsyimgdrag();}).find('img')[0].src;
					
				}else{
					//$('[imgdrag="moveObj"]').remove();
					$('[imgdrag="moveObj"]').animate({left:obj_.offset().left,top:obj_.offset().top - $(window).scrollTop()},200,function(){$(this).remove();obj_.attr('src',oldsrc)});
					//if(obj.attr('imgdrag')!='_img')
						//obj.unbind();
				}
			},
			moveMoust = function(e) {
				if (scrollTimer) {
					clearTimeout(scrollTimer);
					scrollTimer = undefined;
				}
				scrollTimer = setTimeout(function() {

					if(obj_.attr('imgdrag')=='_img'){//如果是上传框中的图片
						
					}else{
						obj_.attr('src',noimg);
					}
					if (arg.hasDown) {
						arg.movemouseX = e.pageX;
						arg.movemouseY = e.pageY;
						moveObj.css({
							"left": arg.movemouseX - arg.mouseImgX + "px",
							"top": arg.movemouseY - $(window).scrollTop() - arg.mouseImgY + "px"
						});
						moveOver();
					}
				}, 1);
				return false;
			},
			downMouse = function(event){
				if(event.which!=1||$('[imgdrag="moveObj"]').length)return;
				var src = $(this)[0].src;
				obj_ = $(this);
				moveObj = $('[imgDrag="moveObj"]').length>0?$('[imgDrag="moveObj"]'):'<div imgDrag="moveObj" class="wodsyDragMoveObj"></div>';
				if(typeof moveObj==='string'){
					$('body').append(moveObj);
					moveObj = $('[imgDrag="moveObj"]');
				}
				moveObj.css({width:obj_.width()+'px',height:obj_.height()+'px',left:obj_.offset().left+'px',top:obj_.offset().top-$(window).scrollTop()+'px'}).empty().append('<img>').find('img').attr('src',src);
				arg = $.extend({
					hasDown:true,
					mouseImgX:event.pageX - obj_.offset().left,
					mouseImgY:event.pageY - obj_.offset().top,
					movemouseX:event.pageX,
					movemouseY:event.pageY
				},arg);
				$(document).unbind().mousemove(moveMoust).mouseup(upMoust);
			};
			obj.each(function(){
				if(haveimg($(this).attr('src')))return;
					$(this).unbind('mousedown').mousedown(downMouse);
			});
			
		}
	});
	$.extend({resetmoveimg:function(){
		if($('[imgDrag="from"]')&&$('[imgDrag="from"]').find('[imgDrag="_img"]'));
			$('[imgDrag="from"]').find('[imgDrag="_img"]').wodsyimgdrag();
		if($('[imgDrag="to"]'))
			$('[imgDrag="to"] img').wodsyimgdrag();
	}})
	
}();